$('.right-titleicon').on("click",function(e){
	projectVM.showMenulist()
})

projectVM = new Vue({
	el: "#content",
	components:{
		personselect,
		processlog
	},
	data: {
		fileIdstraining:'',
		fileIdsTraining2:'',
		trainingfileList:[],
		trainingfileList2:[],
		fileList2:[],
		id:'',
		menuList:[
			{name:'交班',path:'handOver.html'},{name:'接班',path:'carryOn.html'},{name:'列表',path:'index.html'},
		],
		statusTxt:'',
		nowDate:'',
		userInfo:'',
		training:[],
		staffType:0,
		fileList:[],
		chatList:[],
		trainingDrill:[],
		changeValue:'',
		checked:[],
		showSubmit:false,
		onStatus:'',
		result:'',
		showComplete:false,
		memberText:'',
		showMenu:false,
		scanTrainid:'',
		showMorebtn:false,
		staffSpeak:'',
		advance:'',
		showAdd:false,
		show_popup:false,
		list:[{content:'XXX信用XXXX钥匙',status:1,user:'[IP123456]张三2021-6-20'},
		{content:'XXX信用XXXX钥匙',status:2,user:'[IP123456]张三2021-6-20'},
		{content:'XXX信用XXXX钥匙',status:3,user:'[IP123456]张三2021-6-20'}
	]
	},
	created: function() {
		
		this.userInfo = JSON.parse(localStorage.getItem("neiosUser"))
		if(localStorage.getItem('scanTrainid')){
			this.scanTrainid = localStorage.getItem('scanTrainid')
			localStorage.removeItem('scanTrainid')
			this.getScandetail()
		}
		else{
			this.trainingDrill = JSON.parse(localStorage.getItem("trainingDrill"))
			this.statusTxt = this.trainingDrill.statusText 
			this.workId = this.trainingDrill.trainingDrillId
			this.getFileids()
			this.getFileids2()
			this.getDetail()
			if(this.trainingDrill.activityType.indexOf('0') == 0 && this.trainingDrill.status ==1 && this.userInfo.userId.toUpperCase() == this.trainingDrill.hostStaffCode.toUpperCase()){
					this.showComplete = true
			}
			else{
				this.showComplete = false
			}
		}
		
	},
	methods: {
		//保存文件
		saveFile(e,f){
			var that = this
			var param = {
				fileId:e,
				fileType:f,
				fileUserType:'base_info',
				staffType:0,
				trainingDrillId:this.trainingDrillId
			}
			mui.neiosRequst.httpRequst('/app/tranEducation/saveTrainingFileRel', param,
				function(data) {
					console.log(JSON.stringify(data))
					if(data.code == 0){
						that.getFileids()
					}
				},
				function() {
					console.log("查询失败!");
				}
			);
			
		},
		// 上傳
			upload(e) {
				let that = this
				mui.neiosCommon.doUploads(function(ret) {
					if ("0" == ret.code) {
						console.log("成功：" + JSON.stringify(ret))
						that.saveFile(ret.data.fileId,ret.data.fileType)	
						
								
					} else {
						mui.toast('文件上传失败');
					}
				}, function(err) {
					mui.toast('文件上传失败');
				})
			},
			// 删除文件
			delDown(data) {
				let myFileIds = this.fileIds.split(',')
				myFileIds.splice(myFileIds.findIndex(item => item.fileId === data.fileId), 1)
				this.fileIds = myFileIds.join(',')
				console.log(this.fileIds)
				this.getFileList()
			},
			// 下载
			downLoad(data) {
				let url = "/app/common/downloadFile";
				let param = {};
				param.fileId = data.fileId;
				mui.neiosCommon.downLoadFile(param, function(ret) {
					mui.plusReady(function() {
						plus.nativeUI.closeWaiting();
					})
					//调用存储
					var callbackID = plus.bridge.callbackId(function(ret) {
						mui.toast(ret[0])
					}, function(err) {
						mui.toast('文件下载失败')
					});
					plus.bridge.execSync("FileHelper", "doFileSave", [callbackID, ret, data.fileName,
						"Argus3", "Argus4"
					])
				}, function(err) {
					mui.plusReady(function() {
						plus.nativeUI.closeWaiting();
					})
					mui.toast('文件下载失败')
				});
			},
	
		//获取扫描信息
		getScandetail(){
			var that = this
			var param = {
				trainingDrillId:this.scanTrainid,
			}
				mui.neiosRequst.httpRequst('/app/tranEducation/getTrainingDrillById', param,
				function(data) {
					that.trainingDrill = data.data
					console.log(data.data.statusText)
					that.statusTxt = data.data.statusText 
					that.workId = data.data.trainingDrillId
					that.getFileids()
					that.getDetail()
					if(data.data.activityType.indexOf('0') == 0 && data.data.status ==1 && that.userInfo.userId == data.data.hostStaffCode.toUpperCase()){
							that.showComplete = true
					}
					else{
						that.showComplete = false
					}
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
			getFileids2(){
				var that = this
					var param = {
					trainingDrillId:this.trainingDrill.trainingDrillId,
					fileUserType:'activity_scene'
				}
					mui.neiosRequst.httpRequst('/app/tranEducation/getTrainingFileIds', param,
					function(data) {
						
						if(data.data != ''){
							that.fileIdsTraining2 = data.data
							that.getFileList2()
						}	
					},
					function() {
						console.log("查询失败!");
					}
				);
			},
			//获取文件id
			getFileids(){
				var that = this
				var param = {
				trainingDrillId:this.trainingDrill.trainingDrillId,
				fileUserType:'base_info'
			}
				mui.neiosRequst.httpRequst('/app/tranEducation/getTrainingFileIds', param,
				function(data) {
					if(data.data != ''){
						that.fileIdsTraining = data.data
						that.getFileList()
					}	
				},
				function() {
					console.log("查询失败!");
				}
			);
			},
			//获取文件信息
			getFileList(e){
				var param = {
					fileIds:this.fileIdsTraining
				}
				var that = this
				mui.neiosRequst.httpRequst('/app/common/getFileList', param,
				function(data) {
					that.fileList = data.data
				},
				function() {
					console.log("查询失败!");
				}
			);
			},
			getFileList2(e){
				var param = {
					fileIds:this.fileIdsTraining2
				}	
				var that = this
				mui.neiosRequst.httpRequst('/app/common/getFileList', param,
				function(data) {
					that.fileList2 = data.data
				},
				function() {
					console.log("查询失败!");
				}
			);
			},
		//返回上一页
		goBack(){
			mui.back()
		},
		//刷新
		refresh(){
			this.getChat()
			this.getTrainingStaff()
		},
		//获取当前时间
		getDate(){
			var date =new Date()
			var year = date.getFullYear()
			var month =date.getMonth()
			var day = date.getDate()
			var hour = date.getHours()
			var min = date.getMinutes()
			
			if(month.toString().length < 2){
				month = '0'+ month
			}
			if(day.toString().length < 2){
				day = '0'+ day
			}
			if(hour.toString().length < 2){
				hour = '0'+ hour
			}
			if(min.toString().length < 2){
				min = '0'+ min
			}
			this.nowDate = year + '-' + month + '-' + day +' '+hour+':'+min
		},
		//获取发言区人员
		getTrainingStaff(){
			var that = this
			let param = {
				trainingDrillId:this.trainingDrill.trainingDrillId,
				staffType: this.trainingDrill.status == 1?'0':'1',
			}
			mui.neiosRequst.httpRequst('/app/tranEducation/getTrainingStaff', param,
				function(data) {
					that.memberText = data.data

					if(that.memberText.indexOf(that.userInfo.userId) < 0 && that.trainingDrill.hostStaffName != that.userInfo.name){
						if(that.trainingDrill.status == 1){
							that.join()
						}
						if(that.trainingDrill.status == 2){
							that.learn()
						}
						
					}
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//获取留言板
		getChat(){
			var that = this
			let param = {
				trainingDrillId:this.trainingDrill.trainingDrillId
			}
			mui.neiosRequst.httpRequst('/app/tranEducation/queryTrainingSpeak', param,
				function(data) {
					that.chatList = data.data.split('\n')
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//发言
		sendMsg(){
		  if(this.staffSpeak == ''){
			  mui.toast('请输入发言')
			  return
		  }
		  var that = this
		let param = {
			    "trainingSpeak": {
			       trainingDrillId:this.trainingDrill.trainingDrillId,
			       staffType: this.trainingDrill.status == 1?'0':'1',
			       staffSpeak:this.staffSpeak,
			    },
			  dataSource:'NEIOS_APP'+localStorage.getItem("currVersion"),
			  userId:this.userInfo.userId,
			  name:this.userInfo.name
			}
		  mui.neiosRequst.httpRequst('/app/tranEducation/saveTrainingSpeak', param,
		  	function(data) {
				mui.toast('发送成功')
		  		that.staffSpeak = ''
				that.getChat()
		  	},
		  	function() {
		  		console.log("查询失败!");
		  	}
		  );
		},
		//培训完成
		completeTrain(){
			var that = this
			var btnArray= ['否','是']
			mui.confirm('是否完成培训?','确认',btnArray,function(e){
				  if (e.index == 1) {
					  that.complete()
				  }
				  else{
					 
				  }
			})
		},
		//已完成状态提交
		submitAll(){
			var that = this
			var param = {
				training:this.training,
				currentUser:this.userInfo
			}
			// console.log(JSON.stringify(param))
			// return
			mui.neiosRequst.httpRequst('/app/tranEducation/saveTrainingInfo', param,
				function(data) {
					mui.toast('操作成功')
					setTimeout(() => {
						var list = plus.webview.currentWebview().opener();
						　　　　 //触发父页面的自定义事件(refresh),从而进行刷新
						mui.fire(list, 'refresh');
						mui.back()
					}, 1000);
				},
				function() {
					
				})
		},
		//完成接口
		complete(){
			var that = this
			if( this.$refs.personselect.personids != null ||  this.$refs.personselect.personids != ''){
				this.training.viewStaffCode = this.$refs.personselect.personids
				this.training.viewStaffName = this.$refs.personselect.person.split(']')[1]
			}
			
			if(this.training.score == null || this.training.score ==''){
				mui.toast('请输入学习成绩')
				return
			}
			var param = {
				training:this.training,
				trainingDrill:{
					status:2,
					trainingDrillId:this.trainingDrill.trainingDrillId
				},
				currentUser:this.userInfo
			}
			mui.neiosRequst.httpRequst('/app/tranEducation/saveTrainingInfo', param,
				function(data) {
					mui.toast('操作成功')
					setTimeout(() => {
						var list = plus.webview.currentWebview().opener();
						　　　　 //触发父页面的自定义事件(refresh),从而进行刷新
						mui.fire(list, 'refresh');
						mui.back()
					}, 1000);
				},
				function() {
					
				})
		},
		//获取详情
		getDetail(){
			var that = this
			let param = {
				trainingDrillId:this.trainingDrill.trainingDrillId
			}
			mui.neiosRequst.httpRequst('/app/tranEducation/getTrainingById', param,
				function(data) {
					that.training = data.data.training
					if(that.training.viewStaffCode != null && that.training.viewStaffCode != ''){
						that.$refs.personselect.person = '[' +that.training.viewStaffCode+']' +that.training.viewStaffName
					}
					if(data.data.training.status == 2){
						that.staffType = 1
					}
					if(that.trainingDrill.status>0){
						that.getChat()
						that.getTrainingStaff()
					}
					
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//参与
		join(){
			var that = this
			var btnArray= ['否','是']
			mui.confirm('是否确定参与?','确认',btnArray,function(e){
				  if (e.index == 1) {
					  that.joinDrill()
				  }
				  else{
					  mui.back()
				  }
			})
		},
		//补习
		learn(){
			var that = this
			var btnArray= ['否','是']
			mui.confirm('是否确定参与补习?','确认',btnArray,function(e){
				  if (e.index == 1) {
					  that.joinDrill()
					  that.staffType = 1
				  }
				  else{
					  
				  }
			})
		},
		//参与培训
		joinDrill(){
			var that = this
			let param = {
				trainingDrillId:this.trainingDrill.trainingDrillId,
				staffType:this.staffType,
				dataSource:'NEIOS_APP'+localStorage.getItem("currVersion"),
				userId:this.userInfo.userId,
				name:this.userInfo.name
			}
			console.log(JSON.stringify(param),'!!!!!!!!')
			mui.neiosRequst.httpRequst('/app/tranEducation/saveTrainingStaff', param,
				function(data) {
					
					that.getTrainingStaff()
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//返回上一页
		goBack(){
			mui.back()
		},
		//更多按钮
		showMore(){
			this.showMorebtn ? this.showMorebtn = false : this.showMorebtn = true
		},
		//阻止事件冒泡
		clickStop(){

		},
		//选择是否为值班人
		checkOnstatus(){
			console.log(this.onStatus)
			this.onStatus ? this.onStatus = false : this.onStatus =true
			
		},
		//点击菜单
		menuClick(e){
			if(e.name == '我值班'){
				this.onStatus? this.onStatus= false : this.onStatus=true
			}else{
				this.navTo(e.path)
			}
		},
		//左上角菜单显示隐藏
		showMenulist(){
			this.showMenu?this.showMenu=false:this.showMenu=true
		},
		navTo(e){
			mui.openWindow({
					url: e,
					id: e,
			});
			}
	},
	
	})
	
$("#dateSelect3").click(function () {
		    var dtPicker = new mui.DtPicker({ type: 'datetime' });
		    dtPicker.show(function (selectItems) {
				
		       $("#dateSelect3").val(selectItems.text); 
			   projectVM.training.viewTime =selectItems.text
		    })
		})